roundedrect: Mke sure shrinking borders works
authorBenjamin Otte <otte@redhat.com>
Thu, 2 May 2019 17:16:16 +0000 (19:16 +0200)
committerBenjamin Otte <otte@redhat.com>
Thu, 2 May 2019 17:35:45 +0000 (19:35 +0200)
Previously, when borders were too big - ie when a 100x100 rect had only
one 100x100 border, like the black part of ◔ - and then shrinking this
rect by 25px on either side, we'd end up with a 50x50 rect with a 75x75
border, and that's obviously not correct.

gsk/gskroundedrect.c

index 6498a7c48c4024c8b873609f56244055c7950124..9a389b2eb7a7f5ccff6556957cc275ccc399b0d4 100644 (file)
@@ -197,9 +197,10 @@ gsk_rounded_rect_offset (GskRoundedRect *self,
 }
 
 static void
-border_radius_shrink (graphene_size_t *corner,
-                      double           width,
-                      double           height)
+border_radius_shrink (graphene_size_t       *corner,
+                      double                 width,
+                      double                 height,
+                      const graphene_size_t *max)
 {
   if (corner->width > 0)
     corner->width -= width;
@@ -211,6 +212,11 @@ border_radius_shrink (graphene_size_t *corner,
       corner->width = 0;
       corner->height = 0;
     }
+  else
+    {
+      corner->width = MIN (corner->width, max->width);
+      corner->height = MIN (corner->height, max->height);
+    }
 }
 
 /**
@@ -260,10 +266,10 @@ gsk_rounded_rect_shrink (GskRoundedRect *self,
       self->bounds.size.height -= top + bottom;
     }
 
-  border_radius_shrink (&self->corner[GSK_CORNER_TOP_LEFT], left, top);
-  border_radius_shrink (&self->corner[GSK_CORNER_TOP_RIGHT], right, top);
-  border_radius_shrink (&self->corner[GSK_CORNER_BOTTOM_RIGHT], right, bottom);
-  border_radius_shrink (&self->corner[GSK_CORNER_BOTTOM_LEFT], left, bottom);
+  border_radius_shrink (&self->corner[GSK_CORNER_TOP_LEFT], left, top, &self->bounds.size);
+  border_radius_shrink (&self->corner[GSK_CORNER_TOP_RIGHT], right, top, &self->bounds.size);
+  border_radius_shrink (&self->corner[GSK_CORNER_BOTTOM_RIGHT], right, bottom, &self->bounds.size);
+  border_radius_shrink (&self->corner[GSK_CORNER_BOTTOM_LEFT], left, bottom, &self->bounds.size);
 
   return self;
 }